package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Account;
import cn.wolfcode.crm.domain.Attendance;
import cn.wolfcode.crm.mapper.AccountMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IAccountService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class AccountServiceImpl implements IAccountService {

    @Autowired
    private AccountMapper accountMapper;
    
    public int saveOrUpdate(Account record) {
        if (record.getId() == null) {
            return accountMapper.insert(record);
        } else {
            return accountMapper.updateByPrimaryKey(record);
        }
    }
    
    public Account selectByPrimaryKey(Long id) {
        return accountMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageResult query(QueryObject qo) {
        int count = accountMapper.queryForcount(qo);
        if(count == 0){
            new PageResult(0, Collections.EMPTY_LIST);
        }
        List<Attendance> data = accountMapper.queryList(qo);
        return new PageResult(count, data);
    }

    @Override
    public List<Account> selectAll() {
        return accountMapper.selectAll();
    }
}
